﻿using System.Diagnostics.CodeAnalysis;
using Tags.ASF;
using Tags.Objects;

namespace ZenWplExporter
{
	/// <summary>
	/// Reads ASF / WMA Tags
	/// </summary>
	internal class WmaTagReader
	{
		/// <summary>
		/// Gets the music info.
		/// </summary>
		/// <param name="path">The path.</param>
		/// <returns></returns>
		[SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic", Justification = "To keep it the same as Id3TagReaser.")]
		public MusicFileInfo ReadMusicInfo(string path)
		{
			var info = new MusicFileInfo();
			var tag = new AsfTagInfo(path, true);

			info.Title = tag.ContentDescription.Title;

			foreach (Descriptor descriptor in tag.ExContentDescription)
			{
				switch (descriptor.Name)
				{
					case "WM/AlbumTitle":
						info.Album = descriptor.Value.ToString();
						break;
					case "WM/AlbumArtist":
						info.Artist = descriptor.Value.ToString();
						break;
				}
			}

			if (string.IsNullOrEmpty(info.Artist))
			{
				info.Artist = tag.ContentDescription.Author;
			}

			return info;
		}
	}
}